'Copyright (c) 2008, Jonathan Allen

Namespace Collections
#If 1 = 1 Then

	''' <summary>
	''' This creates a new IEqualityComparer object from a pair of functions
	''' </summary>
	''' <typeparam name="T"></typeparam>
	''' <remarks></remarks>
    Public Class QuickEqualityComparer(Of T)
        Implements IEqualityComparer(Of T)

        Private ReadOnly m_EqualityFunction As Func(Of T, T, Boolean)
        Private ReadOnly m_HashingFunction As Func(Of T, Integer)

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="equalityFunction"></param>
        ''' <remarks>The lack of a true hashing function will make this version slow, don't use it when working with dictionaries</remarks>
        
        Sub New(ByVal equalityFunction As Func(Of T, T, Boolean))
            MyClass.New(equalityFunction, Nothing)
        End Sub

        
        Sub New(ByVal equalityFunction As Func(Of T, T, Boolean), ByVal hashingFunction As Func(Of T, Integer))
            If equalityFunction Is Nothing Then Throw New ArgumentNullException("equalityFunction")
            If hashingFunction Is Nothing Then Throw New ArgumentNullException("hashingFunction")

            m_EqualityFunction = equalityFunction
            m_HashingFunction = If(hashingFunction, Function(x As T) 0)
        End Sub

        
        Private Function IEqualityComparer_Equals(ByVal x As T, ByVal y As T) As Boolean Implements Global.System.Collections.Generic.IEqualityComparer(Of T).Equals
            Return m_EqualityFunction(x, y)
        End Function

        
        Private Function IEqualityComparer_GetHashCode(ByVal obj As T) As Integer Implements Global.System.Collections.Generic.IEqualityComparer(Of T).GetHashCode
            Return m_HashingFunction(obj)
        End Function
    End Class
#End If
End Namespace